<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>完善个人信息</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/member.css"/>
    <script type="text/javascript" src="../../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../../script/mobile.js"></script>
    <script type="text/javascript">
        window['adaptive'].desinWidth = 750;
        window['adaptive'].baseFont = 28;
        window['adaptive'].maxWidth = 750;
        window['adaptive'].init();
    </script>
</head>

<body>
<div id="header" style="height: 0.9rem; background: #fff; position: fixed; top: 0;left: 0; width: 100%; z-index: 99">
    <header class="header header-shadow">
        <div class="header-left">
            <div tapmode onclick="comeBack();" class="nav-left"><img class="icon-back" src="../../icon/icon-back.png"/>
            </div>
        </div>
        <h2>完善个人信息</h2>
    </header>
</div>
<div class="header-h" style="padding-top: 1.5rem;"></div>
<section class="html_section pr30 pl30 pb40 perfect_box">
    <!-- 头像-->
    <div class="member_head bg-cover" tapmode onclick="upload()" id="txIcon" data-id=""
         style="background: url('../../icon/Icon.png')">
        <div class="upload-icon"></div>
    </div>
    <ul class="perfect_sex flex_center line_center">
        <li tapmode onclick="chooseSex(1,this)" class="on"><i class="sex_b"></i><span>男</span></li>
        <li tapmode onclick="chooseSex(2,this)"><i class="sex_g"></i><span>女</span></li>
        <li tapmode onclick="chooseSex(3,this)"><span>保密</span></li>
    </ul>
    <ul class="setting_option f26 mt30">
        <li class="between line_center">
            <div class="main-s c-999">昵称</div>
            <input type="text" class="t-r pr30" id="nickname" placeholder="请输入您的昵称" name="">
        </li>
        <li tapmode class="between line_center">
            <div class="main-s c-999">就读城市</div>
            <div class="line_center" tapmode onclick="commonUrl('select_city',{path:'perfect'})"><span
                    id="city">请选择城市</span><img class="ml20 arr_move" src='../../icon/move.png'/></div>
        </li>
        <li tapmode class="between line_center">
            <div class="main-s c-999">学校</div>
            <div class="line_center" tapmode onclick="chooseSchool('select_school')"><span id="school">请选择学校</span><img
                    class="ml20 arr_move" src='../../icon/move.png'/></div>
        </li>
        <li tapmode class="between line_center">
            <div class="main-m c-999">在读阶段</div>
            <div class="line_center" tapmode onclick="commonUrl('select_grade',{type:1})"><span
                    id="grade">请选择在读阶段</span><img class="ml20 arr_move" src='../../icon/move.png'/></div>
        </li>
        <li tapmode class="between line_center">
            <div class="main-m c-999">入学年份</div>
            <div class="line_center" tapmode onclick="commonUrl('select_years',{type:5})"><span
                    id="years">请选择入学年份</span><img class="ml20 arr_move" src='../../icon/move.png'/></div>
        </li>
        <li tapmode class="between line_center">
            <div class="main-m c-999">学科</div>
            <div class="line_center" tapmode onclick="commonUrl('select_subject',{type:3})"><span
                    id="subject">请选择学科</span><img class="ml20 arr_move" src='../../icon/move.png'/></div>
        </li>
    </ul>
    <div class="btn1 mt100" tapmode onclick="submitData()">确定</div>
</section>
</body>

</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">

    var sex = 1;//性别，默认男， 1男 2女 3保密
    var icon = '';//用户头像id
    var name = '';//昵称
    var city = '';//城市id
    var school = '';//学校id
    var grade = '';//在读阶段id
    var years = '';//入学年份id
    var subject = '';//学科id

    apiready = function () {
        setFixStatusBar(); //设置状态栏
        keybackListener()
        api.addEventListener({
            name: 'closeCurrWinIndex'
        }, function (ret, err) {
            api.closeWin();
        });
        //监听参数
        listenr();

    };

    //提交个人信息
    function submitData() {
        var param = {
            token: $api.getStorage('token'),
            type: 1,
            name: $('#nickname').val(),
            sex: sex,
            icon: icon,
            city: city,
            school: school,
            grade_id: grade,
            subject_id: subject,
            entrance_year: years
        };
        console.log(JSON.stringify(param))
        /*if (!isDefine(param.name) || !isDefine(param.city) || !isDefine(param.school) || !isDefine(param.grade_id) || !isDefine(param.subject_id) || !isDefine(param.entrance_year)) {
            pop.notice('请完善个人信息', 2);
            return;
        }*/
        if (!isDefine(param.icon)) {
            pop.notice('请上传头像');
            return;
        }
        if(isDefine(param.name)){
            var len = getLength(param.name);
            if(len > 12){
                pop.notice('最多输入6个汉字或者12个英文或字符');
                return;
            }
        }else {
            pop.notice('请输入昵称');
            return;
        }
        if (!isDefine(param.city)) {
            pop.notice('请选择城市');
            return;
        }
        if (!isDefine(param.school)) {
            pop.notice('请选择学校');
            return;
        }

        pop.loading();
        getAjax(Interface.set_member, param, function (res) {
            console.log(JSON.stringify(res))
            var userInfo = $api.getStorage('userInfo');
            userInfo.status = 1;
            $api.setStorage('userInfo', userInfo);
            if(isDefine(res.data.school_path)){
                $('#school_path').attr('src', ajaxUrl + res.data.school_path);
                $api.setStorage('schoolPath', ajaxUrl + res.data.school_path);
                $api.setStorage('schoolPath_status', 1);
            }else {
                $('#school_path').attr('src', '../../icon/logo.png');
                $api.setStorage('schoolPath', '../../icon/logo.png');
                $api.setStorage('schoolPath_status', 2);
            }
            pop.notice(res.msg)
            pop.close();
            commonUrl('schoolRz_login')
        }, function (error) {
            pop.notice(error.msg)
            pop.close();
        })

    }

    //上传头像
    function upload() {
        uploadHeadPic(function (res) {
            $("#txIcon").css({
                background: 'url(' + ajaxUrl + res.path + ')'
            })
            icon = res.icon;
        })
    }

    //选择学校跳转
    function chooseSchool(path) {
        if (!isDefine(city)) {
            pop.notice('请选择城市', 2);
            return;
        } else {
            var param = {
                type: 4,
                city_id: city
            };
            var pathArr = path.split('/');
            var pathName = pathArr[pathArr.length - 1];
            console.log('当前链接路径：' + jsonChange(path));
            api.openWin({
                name: pathName,
                url: path + '.html',
                reload: true,
                pageParam: param
            });
        }
    }

    //监听参数
    function listenr() {
        //监听城市
        api.addEventListener({
            name: 'city'
        }, function (ret, err) {
            city = ret.value.id;
            $('#city').html(ret.value.name)
        });
        //监听学校
        api.addEventListener({
            name: 'school'
        }, function (ret, err) {
            school = ret.value.id;
            $('#school').html(ret.value.name)
        });
        //监听年级
        api.addEventListener({
            name: 'grade'
        }, function (ret, err) {
            grade = ret.value.id;
            $('#grade').html(ret.value.name)
        });
        //监听入学年份
        api.addEventListener({
            name: 'years'
        }, function (ret, err) {
            years = ret.value.id;
            $('#years').html(ret.value.name + '年')
        });
        //监听学科
        api.addEventListener({
            name: 'subject'
        }, function (ret, err) {
            subject = ret.value.id;
            $('#subject').html(ret.value.name)
        });
    }

    //选择性别
    function chooseSex(sexid, that) {
        sex = sexid
        $(".perfect_sex li").removeClass("on");
        $(that).addClass("on");
    }


    /*$(".perfect_sex li").click(function () {
        $(".perfect_sex li").removeClass("on");
        $(this).addClass("on");
    })*/


</script>
